package cn.itcast.service.impl;

import cn.itcast.entity.AddressBook;
import cn.itcast.mapper.IAddressMapper;
import cn.itcast.service.IAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class AddressServiceImpl implements IAddressService {
    @Autowired
    private IAddressMapper addressMapper;
    @Override
    public List<AddressBook> list(Long userId) {
        return addressMapper.list(userId);
    }

    /**
     * 添加收货地址
     * @param addressBook
     */
    @Override
    public void save(AddressBook addressBook) {
        addressMapper.save(addressBook);
    }

    @Override
    public void updateDefaultAddr(AddressBook addressBook) {
        addressMapper.removeDefaultAdd();
        addressMapper.updateDefaultAddr(addressBook);
    }

    /**
     * 通过id查询地址
     * @param id
     * @return
     */
    @Override
    public AddressBook getById(Long id) {
        return addressMapper.getById(id);
    }

    /**
     * 修改地址
     * @param addressBook
     */
    @Override
    public void updateAddr(AddressBook addressBook) {
        addressMapper.updateAddr(addressBook);
    }

    /**
     * 删除地址
     * @param ids
     */
    @Override
    public void delete(Long ids) {
        addressMapper.delete(ids);
    }

    @Override
    public AddressBook getDefaultAddr() {
        return addressMapper.getDefaultAddr();
    }
}
